package com.cooper.vo;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.cooper.constants.ResourceConstants;

public class BaseVo implements PropertyChangeListener,Serializable{
	
	private static final long serialVersionUID = -7043135263533140960L;
	
	private List<String> changePropertities = new ArrayList<String>();
	
	protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
	
	public BaseVo(){
		changePropertities.clear();
		changeSupport.addPropertyChangeListener(this);
	}
	
	private Long id;
	private String name;
	private String comments;
	private transient String modifier;
	private transient String creator;
	private transient String deleted = ResourceConstants.Deleted.NO;
	private transient Timestamp gmtCreate;
	private transient Timestamp gmtModified;
	@Override
	public String toString(){
		return JSON.toJSONString(this);
	}
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.changeSupport.firePropertyChange("id", this.id, id);
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		changeSupport.firePropertyChange("name", this.name, name);
		this.name = name;
	}

	@Override
	public void propertyChange(PropertyChangeEvent event) {
		changePropertities.add(event.getPropertyName());
	}

	public List<String> getChangePropertities() {
		return changePropertities;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		changeSupport.firePropertyChange("comments", this.comments, comments);
		this.comments = comments;
	}

	public String getModifier() {
		return modifier;
	}

	public void setModifier(String modifier) {
		changeSupport.firePropertyChange("modifier", this.modifier, modifier);
		this.modifier = modifier;
	}

	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		changeSupport.firePropertyChange("creator", this.creator, creator);
		this.creator = creator;
	}

	public Timestamp getGmtCreate() {
		return gmtCreate;
	}

	public void setGmtCreate(Timestamp gmtCreate) {
		changeSupport.firePropertyChange("gmtCreate", this.gmtCreate, gmtCreate);
		this.gmtCreate = gmtCreate;
	}

	public Timestamp getGmtModified() {
		return gmtModified;
	}

	public void setGmtModified(Timestamp gmtModified) {
		changeSupport.firePropertyChange("gmtModified", this.gmtModified, gmtModified);
		this.gmtModified = gmtModified;
	}

	public String getDeleted() {
		return deleted;
	}

	public void setDeleted(String deleted) {
		changeSupport.firePropertyChange("deleted", this.deleted, deleted);
		this.deleted = deleted;
	}
	
	public void clearChangePropertities(){
		changePropertities.clear();
	}

}
